﻿@{
    ViewBag.Title = "VillageIndex";
}
<link href="~/Content/BootstrapSouce/css/bootstrap.css" rel="stylesheet" />
<script src="~/Content/BootstrapSouce/js/jquery.min.js"></script>
<script src="~/Content/BootstrapSouce/js/bootstrap.min.js"></script>
<script src="~/Content/EasyUI/jquery.min.js"></script>

<script>
    
</script>

<div>
    <div class="col-md-12" style="margin-top:10px;height:30px;background-color:#0094ff">

    </div>
    <table class="table table-striped">
        <tr><td>项目案名</td><td><input type="text" id="village_CaseName" /></td></tr>
        <tr><td>来源</td><td><select id="village_Cause"><option value="1">证载</option><option value="2">补办</option><option value="3">合法</option></select></td></tr>
        <tr><td>小区封闭性</td><td><select id="village_Close"><option value="1">封闭居住区</option><option value="2">半封闭居住区</option><option value="3">公开居住区</option></select></td></tr>
        <tr><td>居住小区楼宇结构</td><td><select id="village_Structure"><option value="1">高层住宅小区</option><option value="2">中等住宅小区</option><option value="3">一般住宅小区</option></select></td></tr>
        <tr><td>交通组织方式</td><td><select id="village_Traffic"><option value="1">人车分流</option><option value="2">人车公行</option><option value="3">不管</option></select></td></tr>
        <tr><td>景观及绿化</td><td><select id="village_Green"><option value="1">不错</option><option value="2">一般</option><option value="3">较差</option></select></td></tr>
        <tr><td>容积率</td><td><select id="village_Volume"><option value="1">大于1</option><option value="2">大于2</option><option value="3">大于3</option></select></td></tr>
        <tr><td>车位状况</td><td><select id="village_Parking"><option value="1">专用停车位</option><option value="2">公共停车位</option><option value="3">没有</option></select></td></tr>
        <tr><td>物业公司</td><td><select id="village_Property"><option value="1">专业公司</option><option value="2">地产商</option><option value="3">保安</option></select></td></tr>
        <tr><td>其他</td><td><textarea id="village_Explain" style="width:300px;height:60px;"></textarea></td></tr>
        <tr><td><input id="ins" type="button" value="保存" class="btn btn-success" onclick="Add(1)" /></td><td><input id="upd" type="button" value="保存" class="btn btn-success" onclick="Add(2)" /></td></tr>
    </table>
</div>
<script>
    $("#upd").hide();
    var urls = "http://localhost:63805/";
    var Urls = window.location.href;
    var Sums = Urls.split("=");
    var projectNumber = Sums[1];
    quw(projectNumber);
    function Add(id) {
       
        var village_CaseName = $("#village_CaseName").val();
        var village_Cause = $("#village_Cause").val();

        var village_Close = $("#village_Close").val();
        var village_Structure = $("#village_Structure").val();
        var village_Traffic = $("#village_Traffic").val();
        var village_Green = $("#village_Green").val();

        var village_Volume = $("#village_Volume").val();
        var village_Parking = $("#village_Parking").val();
        var village_Property = $("#village_Property").val();
        var village_Explain = $("#village_Explain").val();
        if (id == 1) {
            $.ajax({
                type: "post",
                url: "http://localhost:63805/apis/Village/VillageAdd",
                data: {
                    projectNumber: projectNumber, village_CaseName: village_CaseName, village_Cause: village_Cause,
                    village_Close: village_Close, village_Structure: village_Structure, village_Traffic: village_Traffic, village_Green: village_Green,
                    village_Volume: village_Volume, village_Parking: village_Parking, village_Property: village_Property, village_Explain: village_Explain
                },
                success: function (obj) {
                    if (obj > 0) {
                        alert("保存成功!");
                        location.href = '/prospect/prospects/' + localStorage.getItem("id");
                    }
                    else {
                        alert("失败!");
                    }
                }
            })
        }
        else
        {
            $.ajax({
                type: "put",
                url: "http://localhost:63805/api/Village/" + projectNumber,
                data: {
                    projectNumber: projectNumber, village_CaseName: village_CaseName, village_Cause: village_Cause,
                    village_Close: village_Close, village_Structure: village_Structure, village_Traffic: village_Traffic, village_Green: village_Green,
                    village_Volume: village_Volume, village_Parking: village_Parking, village_Property: village_Property, village_Explain: village_Explain
                },
                success: function (obj) {
                    if (obj > 0) {
                        alert("修改成功!");
                        location.href = '/prospect/prospects/' + localStorage.getItem("id");
                    }
                    else {
                        alert("失败!");
                    }
                }
            })
        }
    }
    ///进行反填数据并进行数据的判断
    function quw(id) {
        $.ajax({
            url: urls + "api/village/" + id,
            dataType: "json",
            type: "get",
            success: function (obj) {
                if (obj != null)
                {
                    $("#upd").show();
                    $("#ins").hide();
                    var village_CaseName = $("#village_CaseName").val(obj.village_CaseName);
                    var village_Cause = $("#village_Cause").val(obj.village_Cause);

                    var village_Close = $("#village_Close").val(obj.village_Close);
                    var village_Structure = $("#village_Structure").val(obj.village_Structure);
                    var village_Traffic = $("#village_Traffic").val(obj.village_Traffic);
                    var village_Green = $("#village_Green").val(obj.village_Green);

                    var village_Volume = $("#village_Volume").val(obj.village_Volume);
                    var village_Parking = $("#village_Parking").val(obj.village_Parking);
                    var village_Property = $("#village_Property").val(obj.village_Property);
                    var village_Explain = $("#village_Explain").val(obj.village_Explain);
                    
                }
                
            }
        })
    }//小区状况
</script>
